-------------------------------------------------------------------------------
-- Archivo:                      dependency_selection.vhdl
-- Fecha de creación:            18/01/2011
-- Ultima fecha de modificacion: 30/01/2011
-- Diseñador:                    Samantha Gamboa.
-- Diseño:                       dependency_selection
-- Propósito:                    Unidad que verifica si hay dependencia entre  
--                               los registros involucrados en las 
--				 instrucciones en la cola de iinstrucciones.
-------------------------------------------------------------------------------

-- libreria IEEE
library IEEE;
use IEEE.std_logic_1164.all; 

--Diseño de la entidad (caja negra)
entity dependency_selection is
	port(
   	--ENTRADAS
	CURR_OP_i : in std_logic_vector(3 downto 0);
	NEXT_OP_i : in std_logic_vector(3 downto 0);
	EQ45_45_i : in std_logic;
	EQ45_67_i : in std_logic;
	EQ45_89_i : in std_logic;
	EQ67_45_i : in std_logic;
	EQ67_67_i : in std_logic;
	EQ67_89_i : in std_logic;
	EQ89_45_i : in std_logic;
	EQ89_67_i : in std_logic;
	EQ89_89_i : in std_logic;
	--SALIDAS
	HAZARD_o : out std_logic
	);
end dependency_selection;

--Diseño  de especificacion de comportamiento
architecture behavioral of dependency_selection is 
--Declaraciones
	signal aux1 : std_logic;
	signal aux2 : std_logic;
	signal aux3 : std_logic;
	signal aux4 : std_logic;
	signal aux5 : std_logic;
	signal aux6 : std_logic;
begin 
--Comportamiento 

 -- 1:
 --Actual:es Vectorial, constantes, Load 
 --Proximo: Vectorial o FFT
	aux1 <= (CURR_OP_i(3 downto 2) ="00" or CURR_OP_i(3 downto 2) ="01"  
		or CURR_OP_i(3 downto 2) ="10" or CURR_OP_i ="1101") 
	        and (NEXT_OP_i(3 downto 2) ="00" or  NEXT_OP_i(3 downto 2)= "01"
		or NEXT_OP_i= "1111")
	        and (EQ45_67_i or EQ45_89_i);
 --2:
 --Actual:es Vectorial, constantes, load
 --Proximo: Constantes
	aux2 <= (CURR_OP_i(3 downto 2) ="00" or CURR_OP_i(3 downto 2) ="01" 
		or CURR_OP_i(3 downto 2) ="10" or CURR_OP_i ="1101")
		and NEXT_OP_i(3 downto 2) ="10"
        	and EQ45_67_i;

 --3:
 --Actual:es Vectorial, constantes, load
 --Proximo: Store
	aux3 <= (CURR_OP_i(3 downto 2) ="00" or CURR_OP_i(3 downto 2) ="01" 
		or CURR_OP_i(3 downto 2) ="10" or CURR_OP_i ="1101")
		and NEXT_OP_i ="1100"
		and EQ45_45_i;

 --4:
 --Actual: es FFT
 --Proximo: Vectorial o FFT
	aux4 <= CURR_OP_i = "1111" 
		and (NEXT_OP_i(3 downto 2) ="00" or  NEXT_OP_i(3 downto 2)= "01"
		or NEXT_OP_i= "1111")
		and (EQ67_67_i or EQ67_89_i or EQ89_67_i or EQ89_89_i);

 --5:
 --Actual: es FFT
 --Proximo: Constantes
	aux5 <= CURR_OP_i = "1111" and NEXT_OP_i(3 downto 2)= "10"
	and (EQ67_67_i or EQ89_67_i) ;
 
 --6
 --Actual: es FFT
 --Proximo: Store
	aux6<= CURR_OP_i = "1111" and NEXT_OP_i = "1100"
	and (EQ67_45_i or EQ89_45_i) ;


	HAZARD_o <= '1' when (aux1 or aux2 or aux3 or aux4 or aux5 or aux6)  else '0'; 
	
end behavioral;

